#!/usr/bin/env python
###############################################################################
# widgets.py: All widget classes used by mainwindow.
###############################################################################
# Copyright (C) 2010 CERN
#
# Authors: Rohit Yadav <rohityadav89 AT gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
###############################################################################

import wx

class CPUWidget(wx.Panel):
    pos = 0
    def __init__(self, parent, id, col1='#073100', col2='#36ff27'):
        wx.Panel.__init__(self, parent, id, size = (60, 90))
        self.parent = parent
        self.SetBackgroundColour('#000000')
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.darkColour  = col1
        self.lightColour = col2

    def setValue(self, value):
        self.pos = value
        self.Refresh()

    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.SetDeviceOrigin(0, 90)
        dc.SetAxisOrientation(True, True)

        rect = self.pos / 5

        for i in range(1, 21):
            if i > rect:
                dc.SetBrush(wx.Brush(self.darkColour))
                dc.DrawRectangle(4, i*4, 25, 5)
                dc.DrawRectangle(31, i*4, 25, 5)
            else:
                dc.SetBrush(wx.Brush(self.lightColour))
                dc.DrawRectangle(4, i*4, 25, 5)
                dc.DrawRectangle(31, i*4, 25, 5)

